package com.zhht.checkcop.log;

import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.LoggerFactory;

import com.zhbc.framework.utils.StringUtils;

/**
 * 日志注册中心
 * @author ningquan
 *
 */
public class LoggerRegistry {
	
	protected static ConcurrentHashMap<String,com.zhht.checkcop.log.Logger> loggerContext = new ConcurrentHashMap<String,com.zhht.checkcop.log.Logger>();
	private static final org.slf4j.Logger log= LoggerFactory.getLogger(LoggerRegistry.class);
	private static Object _dataLock = new Object();
	private static LoggerRegistry loggerRegistry;
	public  void registLogger(final String name,com.zhht.checkcop.log.Logger logger){
		if(StringUtils.isStrTrimNull(name) || logger == null){
			return;
		}
		boolean isAdd = loggerContext.putIfAbsent(name, logger) == null;
		if(!isAdd){
			log.info("The logger name {} has existed",name);
		}
	}
	
	public  com.zhht.checkcop.log.Logger getContextLogger(final String name){
		if(StringUtils.isStrTrimNull(name)){
			return null;
		}
		return loggerContext.get(name);
	}
	
	public static LoggerRegistry getInstance(){
		if(loggerRegistry == null){
			synchronized (_dataLock) {
				if(loggerRegistry == null){
					loggerRegistry = new LoggerRegistry();
				}
			}
		}
		return loggerRegistry;
	}

}
